with xpa.net.sck; 
with gnat.sockets;
with ada.streams; use ada.streams;
with ada.text_io;

procedure test_sck is
	package sck renames xpa.net.sck;
	hnd: sck.sck_access;

	tgt: sck.addr_type;
	data: stream_element_array(1..40);
	last: stream_element_offset;

	cbuf: string(1..40) := (others => ' ');
	i: stream_element_offset;
	x: positive;

begin
	--addr.addr := gnat.sockets.get_host_by_name("localhost").addresses(1);
	tgt.addr := gnat.sockets.addresses(gnat.sockets.get_host_by_name("localhost"), 1);
	tgt.port := 9931;

	sck.open (hnd, sck.inet4, sck.stream);
	sck.set_connect_timeout (hnd, 10.0);
	sck.set_receive_timeout (hnd, 10.0);
	sck.connect (hnd, tgt);
	sck.receive (hnd, data, last);

	i := data'first;
	x := cbuf'first;	
	loop
		exit when i > last;
		cbuf(x) := character'val(data(i));
		i := i + 1;	
		x := x + 1;
	end loop;	

	ada.text_io.put (last'img);
	ada.text_io.put ("[");
	ada.text_io.put (cbuf);
	ada.text_io.put_line ("]");
	sck.close (hnd);

end test_sck;
